//
//  FFPayTypeItemCell.m
//  LLWallet
//
//  Created by tt on 2020/8/17.
//

#import "FFPayTypeItemCell.h"

@implementation FFPayTypeItemModel

+(FFPayTypeItemModel*) initWithSID:(NSString*)sid title:(NSString*)title icon:(NSData*)icon selected:(BOOL)selected {
    FFPayTypeItemModel *model = [FFPayTypeItemModel new];
    model.sid = sid;
    model.title = title;
    model.icon = icon;
    model.selected = @(selected);
    return model;
}

- (Class)cell {
    return FFPayTypeItemCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}

@end

@interface FFPayTypeItemCell()

@property(nonatomic,strong) UIImageView *iconImgView;
@property(nonatomic,strong) UILabel *titleLbl;
@property(nonatomic,strong) WKCheckBox *checkBox;

@end

@implementation FFPayTypeItemCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 52.0f);
}

- (void)setupUI {
    [super setupUI];
    [self.contentView addSubview:self.iconImgView];
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.checkBox];
}


- (UIImageView *)iconImgView {
    if(!_iconImgView) {
        _iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
        _iconImgView.layer.masksToBounds = YES;
        _iconImgView.layer.cornerRadius = _iconImgView.lim_height/2.0f;
    }
    return _iconImgView;
}

- (UILabel *)titleLbl {
    if(!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
    }
    return _titleLbl;
}

- (WKCheckBox *)checkBox {
    if(!_checkBox) {
        _checkBox = [[WKCheckBox alloc] initWithFrame:CGRectMake(0, 0, 24.0f, 24.0f)];
        _checkBox.onFillColor = [WKApp shared].config.themeColor;
        _checkBox.onCheckColor = [UIColor whiteColor];
        _checkBox.onAnimationType = BEMAnimationTypeBounce;
        _checkBox.offAnimationType = BEMAnimationTypeBounce;
        _checkBox.animationDuration = 0.0f;
        _checkBox.lineWidth = 1.0f;
        [_checkBox setEnabled:NO];
        //    self.checkBox.tintColor = [UIColor grayColor];
    }
    return _checkBox;
}

- (void)refresh:(FFPayTypeItemModel *)model {
    [super refresh:model];
    
    self.titleLbl.text = model.title;
    [self.iconImgView setImage:[UIImage imageWithData:model.icon]];
    [self.titleLbl sizeToFit];
    
    [self.checkBox setOn:model.selected?model.selected.boolValue:false];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.checkBox.lim_top = self.lim_height/2.0f - self.checkBox.lim_height/2.0f;
    self.checkBox.lim_left = 15.0f;
    
    self.iconImgView.lim_top = self.lim_height/2.0f - self.iconImgView.lim_height/2.0f;
    self.iconImgView.lim_left = self.checkBox.lim_right + 15.0f;
    
    self.titleLbl.lim_top = self.lim_height/2.0f - self.titleLbl.lim_height/2.0f;
    self.titleLbl.lim_left = self.iconImgView.lim_right + 15.0f;
    
}

@end
